package com.mind.ridge.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mind.ridge.dto.backend.DishDto;
import com.mind.ridge.pojo.backend.Dish;
import com.mind.ridge.service.backend.DishService;
import com.mind.ridge.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 菜品管理
 *
 * @author Mind
 */
@RestController
@RequestMapping("/dish")
@Slf4j
public class DishController {

    @Resource
    private DishService dishService;

    /**
     * 新增菜品
     *
     * @param dishDto
     * @return
     */
    @PostMapping
    public R<String> save(@RequestBody DishDto dishDto) {
        log.info(dishDto.toString());

        dishService.saveWithFlavor(dishDto);

        return R.success("新增菜品成功");
    }

    @GetMapping("/page")
    public R<IPage> page(int page, int pageSize, String name) {
        return dishService.page(page, pageSize, name);
    }

    @GetMapping("/{id}")
    public R<DishDto> recurInfo(@PathVariable Long id) {
        return dishService.recurInfo(id);
    }

    @DeleteMapping
    public R<String> deleteBatch(@RequestParam List<Long> ids){
        return dishService.deleteBatch(ids);
    }

    @PostMapping("/status/{id}")
    public R<String> alterStatus(@PathVariable int id,@RequestParam List<Long> ids){
        return dishService.alterStatus(id,ids);
    }

    @PutMapping
    public R<String> updateWithFlavor(@RequestBody DishDto dishDto){
        log.info(dishDto.toString());
        return dishService.updateWithFlavor(dishDto);
    }

    @GetMapping("/list")
    public R<List<DishDto>> list(@RequestParam("categoryId") Long id, @Nullable Integer status){
        log.info(id.toString());
        return dishService.categoryList(id,status);
    }
}
